﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Dict.DataModel;
using Dict;

namespace UI
{

    public class UIChapterData
    {
        #region dict
        public string chapter_id;
        public string chapter_name;
        public int chapter_seq;
        public string chapter_icon_res;

        //宝箱条件
        public int[] chapter_box_condition=new int[3];
        public string[] chapter_award_box=new string[3];

        public List<UILevelData> chapter_levels = new List<UILevelData>();
        #endregion

        #region inst
        public bool chapter_inst_get_box_0=false;
        public bool chapter_inst_get_box_1=false;
        public bool chapter_inst_get_box_2=false;
        #endregion

        //当前关卡开启
        public bool chapter_inst_open=false;

        public UIChapterData( TableCopyChapter chapter )
        {
            this.chapter_id = chapter.ChapterId;
            this.chapter_name = TableTextBlo.GetText( chapter.ChapterName );
            this.chapter_seq = chapter.ChapterSequence;
            this.chapter_icon_res = chapter.ChapterIcon;

            this.chapter_box_condition[0] = chapter.BoxCondition0;
            this.chapter_box_condition[1] = chapter.BoxCondition1;
            this.chapter_box_condition[2] = chapter.BoxCondition2;

            this.chapter_award_box[0] = chapter.Box0;
            this.chapter_award_box[1] = chapter.Box1;
            this.chapter_award_box[2] = chapter.Box2;


            //var levels = DictDataManager.Instance.tableCopyMissionDao.GetByOneIndex( chapter_id );
            var levels = Dict.Blo.DictCopyMissionBlo.GetChapterMissionList(chapter_id);

            foreach ( var mission in levels )
            {
                chapter_levels.Add( new UILevelData( mission ) );
            }

            chapter_levels.Sort( ( lh, rh ) =>
            {
                var lh_seq = int.Parse( lh.level_id_number );
                var rh_seq = int.Parse( rh.level_id_number );

                if( lh_seq > rh_seq ) return 1; return -1;
            } );

            int i=0;
            foreach( var level in chapter_levels )
            {
                level.level_seq = ++i;
            }

        }
    }
}
